<template>
  <a-modal
    class="box"
    :visible="visible"
    title="录入完成情况"
    :width="1200"
    @cancel="handleCancel()"
  >
    <a-spin :spinning="loading">
      <a-form-model
        ref="form"
        style="transform: translateX(25%)"
        :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
        :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
        :rules="rules"
        :model="queryParam"
      >
        <a-row>
          <a-col span="12">
            <a-form-model-item
              label="完成类型"
              prop="completeType"
            >
              <a-select
                v-model="queryParam.completeType"
                placeholder="请选择"
                @change="getStatus"
              >
                <a-select-option value="招标完成">
                  招标完成
                </a-select-option>
                <a-select-option value="未招标">
                  未招标
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <div v-if="status">
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="实际招标完成时间"
                prop="biddingCompleteTime"
              >
                <a-date-picker
                  v-model="queryParam.biddingCompleteTime"
                  type="date"
                  value-format="YYYY-MM-DD"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="招标完成情况说明"
                prop="biddingCompleteRemark"
              >
                <BaseInput
                  v-model.trim="queryParam.biddingCompleteRemark"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="分包商选择方式"
                prop="subcontractorsSelect"
              >
                <a-select
                  v-model="queryParam.subcontractorsSelect"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in subcontractor"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="分包方式"
                prop="branchPackMode"
              >
                <a-select
                  v-model="queryParam.branchPackMode"
                  placeholder="请选择"
                  default-value="0"
                >
                  <a-select-option
                    v-for="item in subcontractingMethod"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="拟定队伍数量"
                prop="teamsNum"
              >
                <BaseInput
                  v-model.trim="queryParam.teamsNum"
                  :max-length="9"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="招标合同额"
                prop="tenderContractMoney"
              >
                <BaseInputNumber
                  v-model.trim="queryParam.tenderContractMoney"
                  :min="0"
                  :max="1000000000000"
                  :precision="2"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="分包工程招标内容"
                prop="branchProjectBiddingContent"
              >
                <BaseTextarea
                  v-model.trim="queryParam.branchProjectBiddingContent"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item label="附件">
                <b-upload
                  upload-type="single"
                  business-code="MM01"
                  :file-list.sync="queryParam.completeFileInfoVo"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
        <div v-if="!status">
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="是否甲方原因"
                prop="reason"
              >
                <a-radio-group v-model="queryParam.reason">
                  <a-radio value="是">
                    是
                  </a-radio>
                  <a-radio
                    value="否"
                    style="margin-left: 50px"
                  >
                    否
                  </a-radio>
                </a-radio-group>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="未按计划招标情况说明"
                prop="noPlanBiddingRemark"
              >
                <BaseInput
                  v-model.trim="queryParam.noPlanBiddingRemark"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item
                label="后期工作安排"
                prop="workArrangement"
              >
                <BaseInput
                  v-model.trim="queryParam.workArrangement"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item label="附件">
                <b-upload
                  upload-type="single"
                  business-code="MM01"
                  :file-list.sync="queryParam.notCompleteFileInfoVo"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button
        key="back"
        @click="handleCancel()"
      >
        取消
      </a-button>
      <template v-if="!status">
        <a-button
          key="submit"
          type="primary"
          :loading="loading"
          @click="handleOk(queryParam, 'SUBMITTED')"
        >
          提交
        </a-button>
        <!-- <a-button
          key="other"
          type="primary"
          :loading="loading"
          @click="handleOk(queryParam, 'PAST')"
        >
          保存
        </a-button> -->
      </template>
      <a-button
        v-else
        key="submit"
        type="primary"
        :loading="loading"
        @click="handleOk(queryParam, 'PAST')"
      >
        提交
      </a-button>
    </template>
  </a-modal>
</template>

<script>
import { getDropDown, getDropDown2 } from '@/api/dropDown'
import { getCompleteDetails, inpurComplete } from '@/api/legal'

export default {
    name: 'Carryout',
    props: {
        id: {
            type: String
        },
        visible: {
            type: Boolean,
            default: () => false
        }
    },
    data() {
        return {
            loading: false,
            status: true,
            rules: {
                completeType: [{ required: true, message: '请选择完成类型', trigger: 'change' }],
                subcontractorsSelect: [{ required: true, message: '请选择分包商选择方式', trigger: 'change' }],
                branchPackMode: [{ required: true, message: '请选择分包方式', trigger: 'change' }],
                biddingCompleteTime: [{ required: true, message: '请选择实际招标完成时间', trigger: 'change' }],
                biddingCompleteRemark: [{ required: true, message: '请输入招标完成情况说明', trigger: 'change' }],
                workArrangement: [{ required: true, message: '请输入后期的工作安排', trigger: 'change' }],
                // noPlanBiddingRemark: [{required: true, message: '请输入未按计划招标情况说明', trigger: 'change'}],
                teamsNum: [{ required: true, message: '请输入拟定的队伍数量', trigger: 'change' }],
                branchProjectBiddingContent: [{ required: true, message: '请输入分包工程招标内容', trigger: 'change' }],
                reason: [{ required: true, message: '请选择原因', trigger: 'change' }],
                tenderContractMoney: [{ required: true, message: '请输入招标合同额度', trigger: 'change' }]
            },
            queryParam: {
                completeFileInfoVo: {},
                notCompleteFileInfoVo: {}
            },
            subcontractor: [],
            subcontractingMethod: []
        }
    },
    created() {
        this.getSubcontractor()
        this.getSubcontractingMethod()
    },
    watch: {
        visible(e) {
          console.log(e)
            if (!e) {
                this.queryParam = {
                    completeFileInfoVo: {},
                    notCompleteFileInfoVo: {}
                }
                this.$refs.form.clearValidate()
            } else {
                // getCompleteDetails({ id: this.id }).then((res) => {
                //     if (res.code === 200) {
                //         this.queryParam.branchPackMode = res.data.biddingPlanDerails.branchPackModeId
                //         this.queryParam.subcontractorsSelect = res.data.biddingPlanDerails.subcontractorsSelectId
                //         this.queryParam.teamsNum = res.data.biddingPlanDerails.ranksNum
                //         this.queryParam.tenderContractMoney = res.data.biddingPlanCompleteDetails.tenderContractMoney
                //         this.queryParam.branchProjectBiddingContent = res.data.biddingPlanCompleteDetails.biddingContent
                //         this.queryParam.biddingCompleteRemark = res.data.biddingPlanCompleteDetails.biddingCompleteRemark
                //     }
                // })
            }
        }
    },
    methods: {
        getStatus(value) {
            this.queryParam = {
                completeFileInfoVo: {},
                notCompleteFileInfoVo: {}
            }
            switch (value) {
                case '招标完成':
                    this.status = true
                    this.queryParam.completeType = '招标完成'
                    break
                case '未招标':
                    this.status = false
                    this.queryParam.completeType = '未招标'
                    break
            }
        },
        getSubcontractor() {
            let query = { type: 1 }
            getDropDown2({ query: query }).then((res) => {
                this.subcontractor = res.data
            })
        },
        getSubcontractingMethod() {
            let query = { type: 0 }
            getDropDown2({ query: query }).then((res) => {
                this.subcontractingMethod = res.data
            })
        },
        handleCancel() {
            this.$emit('update:visible', false)
            this.$refs.form.clearValidate()
            this.queryParam = {
                completeFileInfoVo: {},
                notCompleteFileInfoVo: {}
            }
        },
        handleOk(subQueryParam, status) {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true
                    subQueryParam.id = this.id
                    subQueryParam.auditStatus = status
                    inpurComplete(subQueryParam).then((res) => {
                        if (res.code === 200) {
                            status == 'SUBMITTED'
                                ? this.$message.success('提交成功')
                                : this.$message.success('保存成功')

                            this.$emit('ok')
                            this.handleCancel()
                        } else {
                            this.$message.error('提交失败')
                        }
                        this.loading = false
                    })
                } else {
                  this.$message.warning("请填写完所有必填项信息")
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
/deep/ .ant-modal-header {
    text-align: center;
}

/deep/ .ant-modal-header .ant-modal-title {
    font-weight: 800;
}
</style>
